/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package FeeDeposit;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Mukesh
 */
public class PaymodeWiseReport extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {

            int paymode = 0;
            if (request.getParameter("paymode").length() != 0) {
                paymode = Integer.parseInt(request.getParameter("paymode"));
            }

            Vector<Object> list = FeeDeposit.Query.viewAll("fd.pay_mode", paymode);
            if (!list.isEmpty()) {
                Iterator it = list.iterator();
                float total = 0;
                while (it.hasNext()) {
                    FeeDepositBean fdb = (FeeDepositBean) it.next();
                    FeeType.FeeTypeBean ftb = fdb.getFeeTypeBean();
                    out.println("<tr id='" + fdb.getFeesDepositId() + "'>");
                    out.println("<td><center>");
                    out.println(fdb.getAdmissionId());
                    out.println("</center></td>");
                    out.println("<td><center>");
                    out.println(fdb.getStuName());
                    out.println("</center></td>");
                    out.println("<td><center>");
                    out.println(ftb.getFeeTypeName());
                    out.println("</center></td>");
                    out.println("<td><center>");
                    out.println(fdb.getDod());
                    out.println("</center></td>");
                    out.println("<td><center>");
                    out.println(fdb.getAmount());
                    out.println("</center></td>");
                    out.println("</tr>");
                    total = total + fdb.getAmount();
                }
                out.println("<tr style='font-weight: bold;'><td colspan='4' style='text-align:center'>Total</td>");
                out.println("<td style='text-align:center'>" + total + "</td></tr>");
            } else {
                out.println("<tr>");
                out.println("<td colspan='3'>");
                out.println("<b>No Record Found</b>");
                out.println("</td>");
                out.println("</tr>");
            }
        } catch (Exception e) {
            out.println("<tr>");
            out.println("<td colspan='3'>");
            out.println("<b>No Record Found(e)</b>");
            out.println("</td>");
            out.println("</tr>");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
